package controllers;

import models.Community;
import models.Idea;
import models.User;
import play.mvc.Controller;

public class ShareIdea extends Controller {

	/**
	 * Getting the community name calling the method shareIdeaInCommunity to
	 * share the specified idea in it.
	 * 
	 * @param id
	 *            id of the idea to be shared.
	 * @author Ismail Omar
	 */
	public static void shareIdea(Long id) {

		Idea idea = Idea.findById(id);

		String userId = session.get("userId");
		Long userIdOne = Long.parseLong(userId);
		User user = User.findById(userIdOne);

		String communityName = params.get("communityNameBox");
		if (user.ownedCommunityList.size() == 0) {
			System.out.println("No communities to share in");
		}
		for (int counter = 0; counter < user.ownedCommunityList.size(); counter++) {
			if (user.ownedCommunityList.get(counter).name.equalsIgnoreCase(communityName)) {
				Community community = user.ownedCommunityList.get(counter);
				idea.shareIdeaInCommunity(user, community);
				render(user, idea, community);
			}
		}
		System.out.println("No communities Found");
	}

}
